package com.matt.repository.rel;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import com.matt.domain.rel.RelClassesChildren;
import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/14
 * *******************************
 */
public interface RelClassesChildrenRepository extends JpaRepository<RelClassesChildren, String>{

    @Modifying
    @Transactional
    @Query(value="delete from RelClassesChildren c where c.classesId = ?1")
    void deleteByClassesId(String classesId);

    @Modifying
    @Transactional
    @Query(value = "delete from RelClassesChildren c where c.childrenId = ?1")
    void deleteByChildrenId(String childrenId);

    Long countByClassesIdAndStatus(String classesId,Integer status);

    List<RelClassesChildren> findByChildrenIdIn(List<String> childrenId);

    List<RelClassesChildren> findByChildrenId(String childrenId);

    RelClassesChildren findFirstByChildrenId(String childrenId);

    List<RelClassesChildren> findAllByClassesIdIn(List<String> classesId);

    List<RelClassesChildren> findAllByClassesId(String classesId);

    @Modifying
    @Transactional
    @Query(value = "delete from RelClassesChildren c where c.childrenId =:childrenId and c.classesId=:classesId")
    void deleteByChildrenIdAndAndClassesId(@Param("childrenId") String childrenId, @Param("classesId") String classesId);

    List<RelClassesChildren> findAllByClassesIdAndStatus(String classesId, int i);
}
